<template>
  <div class="home">
    <el-button v-preventReClick type="danger" @click="open">danger</el-button>
    <el-button type="primary" @click="openConfirm">confirm</el-button>
    <MaskCpm></MaskCpm>
    <el-button type="success" @click="getCurrency('130#122,127#1221',currencyData,'Zh')">获取两个货币</el-button>
    <change-item></change-item>
  </div>
</template>

<script>
import MaskCpm from "@/components/MaskCpm";
import ChangeItem from "@/views/changeItem";
export default {
  name: 'HomeView',
  components:{
    ChangeItem,
    MaskCpm
  },
  data(){
    return {
      result:[],
      timer:'',
      workTimeList:[
        {nikeName:'李欣蔚',sumHourWork:'120'},
        {nikeName:'分割线',sumHourWork:'168'},
        // {nikeName:'李宏宇',sumHourWork:'48'},
      ],
      currencyData: [
        {"superior":"0","createtime":"2019-08-19 18:02:52","name":"人民币","shipcoinclassificationid":127,"nameen":"RMB","delflag":"1"},
        {"superior":"0","createtime":"2019-08-19 18:02:57","name":"美元","shipcoinclassificationid":128,"nameen":"USD","delflag":"1"},
        {"superior":"0","createtime":"2020-11-11 14:47:38","name":"港元","shipcoinclassificationid":129,"nameen":"HKD","delflag":"1"},
        {"superior":"0","createtime":"2020-11-13 11:40:46","name":"欧元","shipcoinclassificationid":130,"nameen":"EUR","delflag":"1"}]
    }
  },
  mounted() {

  },
  methods:{
    openConfirm(){
      this.$cusConfirm({
        message: '您的报价是当前最高价，您是否确认继续加价？',
      }).then(() => {
        console.log('确认')
      }).catch(()=>{
        console.log('取消')
      });
    },
    open(){
      console.log(1)
    },
    getCurrency(oldStr, currencyData, lang){
      var currency = [];
      var newStr = [];
      oldStr = oldStr.split(",")
      for (let i in oldStr) {
        var obj = oldStr[i].split('#')[0];
        for (let j in currencyData) {
          if (obj == currencyData[j].shipcoinclassificationid) {
            if (lang == 'Zh') {
              currency.push(currencyData[j].nameen + '' + oldStr[i].split('#')[1] + '万');
            }
            if (lang == 'En') {
              var arr = oldStr[i].split('#')[1] + ''
              arr = arr.split('.');
              if (arr.length == 2) {
                let zhengshu = arr[0];  //获取整数部分
                let xiaoshu = arr[1];   //获取小数部分
                var num
                if (xiaoshu.length == 2) {
                  let value = (zhengshu + xiaoshu) * 100;
                  num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');

                }else if (xiaoshu.length == 3) {
                  let value = (zhengshu + xiaoshu) * 10;
                  num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');

                }else if (xiaoshu.length == 4) {
                  let value = (zhengshu + xiaoshu) * 1;
                  num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
                }
                else {
                  num = (zhengshu + xiaoshu) * 1000;
                }
                currency.push(currencyData[j].name + '' + num);
              } else {
                num = oldStr[i].split('#')[1] * 10000;
                currency.push(currencyData[j].name + '' + ((num.toString().indexOf('.') !== -1) ? num.toLocaleString() : num.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')));
              }
            }
          }
        }
      }
      for (let u in currency) {
        if (lang == 'Zh') {
          newStr += currency[u] + ' 或 '
        }
        if (lang == 'En') {
          newStr += currency[u] + ' or '
        }
      }
      if (newStr.length > 0) {
        newStr = newStr.substr(0, newStr.length - 3);
      }
      console.log(newStr,'最后结果')
      return newStr;

    }
  }
}
</script>
<style scoped lang="scss">
.test-font{
  font-family: "cusAlibaba";
  font-size: 20px;
}
</style>
